#!/bin/sh

FILES=$(find . -type f -name '*.*')
for f in $FILES
do
    if test -f $f; then
        CHARSET="$( file -bi "$f"|awk -F "=" '{print $2}')"
        if [ "$CHARSET" != utf-8 ]; then
            echo -e "\nConverting $f from $CHARSET to utf-8"
            # iconv -f "$CHARSET" -t utf-8 "$f" -o "$f.temp"
            iconv -f GBK -t UTF-8 "$f" -o "$f.temp"
            mv -f "$f.temp" $f
        fi
    else
        echo -e "\nSkipping $f - it's a regular file";
    fi
done


#!/bin/bash

// batch_change_GB2312_to_UTF-8

cd directory
find ./ -type f -name "*.java" | while read line;do
echo $line
iconv -f GB2312 -t UTF-8 $line > ${line}.utf8
mv $line ${line}.gb2312
mv ${line}.utf8 $line
done


find . -name *.java -exec sh -c "iconv -f GBK -t UTF8 {} > /tmp/iconv.tmp" \; -exec mv /tmp/iconv.tmp '{}' \;